package com.bw.hongye.other.controller;

import com.aliyun.common.utils.PageUtils;
import com.aliyun.common.utils.R;
import com.bw.hongye.other.entity.CityEntity;
import com.bw.hongye.other.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author tZhe
 * @email tZhe@hongye.com
 * @date 2021-07-23 14:24:49
 */
@CrossOrigin
@RestController
@RequestMapping("other/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = cityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CityEntity city = cityService.getById(id);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CityEntity city){
		cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CityEntity city){
		cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		cityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/findParentId/{parentId}")
    public ArrayList<CityEntity> findParentId(@PathVariable Integer parentId){
        return cityService.findParentId(parentId);
    }

}
